import { createPinia } from 'pinia'
import persist from 'pinia-plugin-persistedstate'

const pinia = createPinia()
pinia.use(persist)

export default pinia


import { defineStore } from 'pinia'
import { ref } from 'vue'
export const usePaperStore = defineStore('Paper', () => {
  const paperData = ref([])
  return {
    paperData
  }
})
export const useSubjectStore = defineStore('Subject', () => {
  const IsInSubject = ref(true)
  const currentSubjectId = ref()
  const toggleISInSubject = () => {
    IsInSubject.value = !IsInSubject.value
  }
  return {
    IsInSubject,
    currentSubjectId,
    toggleISInSubject
  }
})

//用户模块token setToken removeToke
export const userUserStore = defineStore(
  'userToken',
  () => {
    const token = ref('')
    // 清除token
    const setToken = (newToken) => {
      token.value = newToken
      localStorage.setItem('token', newToken)
    }
    const setRole = (role) => {
      localStorage.setItem('role', role)
    }
    const getRole = () => {
      // console.log('进入到仓库获取role');
      return localStorage.getItem('role')
    }

    // 存储用户信息
    const user = ref({})
    const getUser = async () => {
      //   const res = await userGetInfoServe()
      //   console.log(res)
      //   user.value = res.data.data
    }

    // 清除User用户信息
    const setUser = (obj) => {
      user.value = obj
    }


    //获取科目id
    const getSubId = () => {
      const route = useRoute();
      const subId = route.params.subId;
      return subId
    }

    return {
      setToken,
      token,
      user,
      getUser,
      setUser,
      setRole,
      getRole,
      getSubId
    }
  },
  {
    persist: true
  }
)

// import { userUserStore } from './modules/user'
// export { userUserStore }
//相当于上面那两行接收所有的按需导出
export * from './modules/user'
export * from './modules/class'
